/*
 * Copyright 2002-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.jteam.jsa.core;

import java.util.Set;

/**
 * Represents a document in a search engine corpus. A document is a {@link Boostable boostable} search element. Each
 * document is associated with a identifier. This identifier is unique within the corpus and never changes once it is set.
 *
 * @author Uri Boness
 */
public interface Document extends Boostable {

    /**
     * The id of this document.
     *
     * @return The id of this document.
     */
    Object getId();

    /**
     * The type of this document. Document types are used to group documents that represent the same data set.
     *
     * @return The type of this document.
     */
    String getType();

    /**
     * A convinience method to return the single value of the field identified by the given field name. If a field
     * has more than one value associated with it, the first value is returns (see {@link Field#getValue()}).
     *
     * @param name The name of the field of which the value is returned.
     * @return The single value of the field identified by the given field name.
     */
    Object getFieldValue(String name);

    /**
     * A convenience method to return all values of the field identified by the given field name.
     *
     * @param name The name of the field of which the values are returned.
     * @return The values of the field identified by the given field name or <code>null</code> if no such field could be found.
     */
    Set<Object> getFieldValues(String name);

    /**
     * Returns the field associated with the given field name.
     *
     * @param name The name of the returned field.
     * @return The field associated with the given field name or <code>null</code> if no such field is found.
     */
    Field getField(String name);

    /**
     * Returns a set of all fields in this document. The returned set should/can not be modified, use any of the
     * <code>addField(...)</code> methods to add fields to this document.
     *
     * @return a set of all fields in this document.
     */
    Set<Field> getFields();

}
